﻿using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using appladen.contracts;
using appladen.contracts.data;

namespace appladen.gui.ViewModels
{
    public class ViewModel : IViewmodel, INotifyPropertyChanged
    {
        
        private DataTable _table;

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        #endregion

        #region IViewmodel Members

        public void ÖffneDatei(string filename)
        {
            Öffne_Datei(filename);
        }

        public void Vorwärts()
        {
            Trace.TraceInformation("Vorwärts immer");
            Vor();
        }

        public void Rückwärts()
        {
            Trace.TraceInformation("Rückwärts nimmer");
            Zurück();
        }

        public void DatensatzAnzeigen(int index)
        {
             Trace.TraceInformation("Datensatz Anzeigen");
            var ds = new Datensatz
            {Id = index, Header = Table.Columns.Cast<DataColumn>().Select(c => c.ColumnName), Werte = Table.Rows[ index].ItemArray.Cast<string>()};
            Datensatz_anzeigen(ds);
        }


        public DataTable Table
        {
            get { return _table; }
            set
            {
                _table = value;
                PropertyChanged(this, new PropertyChangedEventArgs("Table"));
            }
        }
        public event Action<string> Öffne_Datei;
        public event Action Vor;
        public event Action Zurück;
        public event Action<Datensatz> Datensatz_anzeigen;

        #endregion
    }
}